define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    var table = $("#table_" + $(this).data("id"));
                    table.bootstrapTable({
                        url: 'teacher/ranking/index?id=' + $(this).data("id"),
                        toolbar: '#toolbar_' + $(this).data("id"),
                        sortName: 'id',
                        search: false,
                        commonSearch: true,
                        searchFormVisible: true,
                        columns: [
                            [
                                {field: 'sort', title: '排名', operate:false,},
                                {field: 'name', title: '老师姓名', operate:false,},
                                {field: 'mobile', title: '手机号', operate:false,},
                                {field: 'score', title: '分数', operate:false,},
                                {
                                    field: 'created_at',
                                    title: __('Create time'),
                                    sortable: false,
                                    formatter: Table.api.formatter.datetime,
                                    operate: 'RANGE',
                                    addclass: 'datetimerange',
                                    visible:false
                                },
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });
                    Table.api.bindevent(table);

                    $(this).on('click', function (e) {
                        panel.find(".btn-refresh").trigger("click");
                    });

                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});